#include "ScubaSoldierBullet.h"
#include "Box.h"
#include "RSManager.h"
#include "Sprite.h"
#include "ShareComponents.h"
#include "Camera.h"
#include "MainGame.h"

ScubaSoldierBullet::ScubaSoldierBullet(Box* box, float angle, float heightLevel) : Object(box, Obj_Anti), MoveObject()
{	
	_sprite = RSManager::getInstance()->getSprite(GRENADE);
	_box->_size = _sprite->getRenderSize();
	_angle = angle;
	_heightLevel = heightLevel;
	AssignMove(_box);		
	_hits = 1;
	_isAlive = true;	
}

ScubaSoldierBullet::~ScubaSoldierBullet(void)
{
}

void ScubaSoldierBullet::update()
{
	if(_hits <= 0 || _box->_position.y < gl_camera->getTop())	
		_isAlive = false;		
	if (_angle == 0)
	{
		if(_heightLevel - _box->_position.y >= 100)
			_box->_position.y += (_heightLevel - _box->_position.y) * 0.1f;
		else		
		{
			_isAlive = false;	
			ScubaSoldierBullet* _left = new ScubaSoldierBullet(new Box(_box->_position, D3DXVECTOR2(0, 0), D3DXVECTOR2(2.5f, 2.5f)), 135, 0);	
			ScubaSoldierBullet* _right = new ScubaSoldierBullet(new Box(_box->_position, D3DXVECTOR2(0, 0), D3DXVECTOR2(2.5f, 2.5f)), 35, 0);
			ScubaSoldierBullet* _down = new ScubaSoldierBullet(new Box(_box->_position, D3DXVECTOR2(0, 0), D3DXVECTOR2(2.5f, 2.5f)), 90, 0);
			gl_MainGame->addWorldObject(_left);
			gl_MainGame->addWorldObject(_right);
			gl_MainGame->addWorldObject(_down);
		}
	}
	else
		if(!moveDiagonalThrowCollide(_angle))
			_isAlive = false;
}

void ScubaSoldierBullet::render()
{	
	_sprite->Render(_box->_position);
}

Box* ScubaSoldierBullet::getCollisionBox()
{
	_colBox->_position = _box->_position;
	_colBox->_size = _box->_size;
	_colBox->_v = _box->_v;
	return _colBox;
}

